package cn.kgc.spring01.factory;

import com.mysql.jdbc.Driver;
import org.springframework.beans.factory.FactoryBean;

import javax.security.auth.login.Configuration;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/2/17
 * @Description:  获取连接的工厂对象
 * FactoryBean <T>  获取对象的类型
 */
public class ConnectionBeanFactory implements FactoryBean<Connection> {


    // 托管 ConnectionBeanFactory    - > Connection
    @Override
    public Connection getObject() throws Exception {
        System.out.println("-----------------------------");
        Driver driver = new Driver();
        DriverManager.registerDriver(driver);
        Connection connection = DriverManager.getConnection("jdbc:mysql:///java2218", "root", "root");
        return connection;
    }

    // 返回生成bean的Class类型
    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }
}
